//
//  OrderInfoTableViewCell.m
//  BaseFrame
//
//  Created by 孟学浩 on 2017/4/5.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "OrderInfoTableViewCell.h"

@interface OrderInfoTableViewCell()

@property (nonatomic,strong) UIImageView *imgView;
@property (nonatomic,strong) UILabel *infoLabel;
@property (nonatomic,strong) UILabel *countLabel;

@end

@implementation OrderInfoTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = 0;
        self.separatorInset = UIEdgeInsetsZero;
        if ([self respondsToSelector:@selector(setLayoutMargins:)]) {
            self.layoutMargins = UIEdgeInsetsZero;
        }
        _imgView = [UIImageView new];
        _imgView.backgroundColor = [UIColor redColor];
        
        _infoLabel = [UILabel new];
        _infoLabel.numberOfLines = 0;
        _infoLabel.font = DEF_FontSize_13;
        
        _countLabel = [UILabel new];
        _countLabel.numberOfLines = 0;
        
        [self.contentView addSubview:_imgView];
        [self.contentView addSubview:_infoLabel];
        [self.contentView addSubview:_countLabel];
    }
    
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _imgView.frame = CGRectMake(15, 0, self.frame.size.height-15, self.frame.size.height-15);
    _imgView.center = CGPointMake(_imgView.center.x, self.frame.size.height/2.);
    
    _infoLabel.frame = CGRectMake(CGRectGetMaxX(_imgView.frame)+5, 0, SCREEN_WIDTH - CGRectGetMaxX(_imgView.frame) - 60, self.frame.size.height);
    _countLabel.frame = CGRectMake(SCREEN_WIDTH-110, 0, 100, self.frame.size.height);
    _countLabel.center = CGPointMake(_countLabel.center.x, self.frame.size.height/2.);
}

- (void)setDataDictionary:(NSDictionary *)dataDictionary{
    _dataDictionary = dataDictionary;
    _imgView.image = [UIImage imageNamed:@"img"];
    NSString *temp0 = @"已完成\n总价   ¥3600";
    NSMutableAttributedString *attStr0 = [[NSMutableAttributedString alloc] initWithString:temp0];
    [attStr0 addAttribute:NSForegroundColorAttributeName value:getColor(@"545454") range:NSMakeRange(0, [temp0 length])];
    NSMutableParagraphStyle *paragraphStyle0 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle0 setLineSpacing:5];//调整行间距
    [attStr0 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle0 range:NSMakeRange(0, [temp0 length])];
    _countLabel.attributedText = attStr0;
    _countLabel.textColor = getColor(redColor);
    _countLabel.font = DEF_FontSize_12;
    _countLabel.textAlignment = NSTextAlignmentRight;
    
    NSString *title = @"榨汁机";
    NSString *info = @"数量 25";
    NSString *money = @"价格 ¥1200";
    NSString *temp = [NSString stringWithFormat:@"%@\n%@\n%@",title,info,money];
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:temp];
    [attStr addAttribute:NSForegroundColorAttributeName value:getColor(@"545454") range:NSMakeRange(0, [temp length])];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:4];//调整行间距
    [attStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [temp length])];
    
    _infoLabel.attributedText = attStr;
}

- (void)setModel:(GoodsAddOrderModel *)model{
    _model = model;
    
    [_imgView sd_setImageWithURL:[NSURL URLOffsetIPWithString:_model.commodityImg] placeholderImage:[UIImage imageNamed:@"image"]];
    NSString *temp0 = [NSString stringWithFormat:@"已完成\n总价   ¥%.2lf",[_model.commodityNum intValue] * [_model.commodityPrice floatValue]];
    NSMutableAttributedString *attStr0 = [[NSMutableAttributedString alloc] initWithString:temp0];
    [attStr0 addAttribute:NSForegroundColorAttributeName value:getColor(@"545454") range:NSMakeRange(0, [temp0 length])];
    NSMutableParagraphStyle *paragraphStyle0 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle0 setLineSpacing:5];//调整行间距
    [attStr0 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle0 range:NSMakeRange(0, [temp0 length])];
    _countLabel.attributedText = attStr0;
    _countLabel.textColor = getColor(redColor);
    _countLabel.font = DEF_FontSize_12;
    _countLabel.textAlignment = NSTextAlignmentRight;
    
    NSString *title = _model.commodityName;
    NSString *info = [NSString stringWithFormat:@"数量 %@",_model.commodityNum];
    NSString *money = [NSString stringWithFormat:@"价格 ¥%@",_model.commodityPrice];
    NSString *temp = [NSString stringWithFormat:@"%@\n%@\n%@",title,info,money];
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:temp];
    [attStr addAttribute:NSForegroundColorAttributeName value:getColor(@"545454") range:NSMakeRange(0, [temp length])];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:4];//调整行间距
    [attStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [temp length])];
    
    _infoLabel.attributedText = attStr;
}

@end
